<?php

/** Esta clase es la encargada del manejo de los datos de la tabla type_services  **/

class ServiceType 
{
	/**
	 *	@access  public
	 *	@author <Oscar Mauricio Mejía>
	 */
			
	public function __construct ()
	{
	
	
	}
	
	
    /**
	 * Esta funcion se encarga de agregar los tipos de servicios obtenidos desde las apis.		    
	 * @access public
	 * @return true or false
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function addServiceType($data,$codigo=-1)
	{
		//$codigo = -1 // inserta
		//$codigo !=-1 //actualiza
		
	 if($codigo==-1){	
		$values= "($data->ser_type_code_api,'".$data->ser_type_name."','".$data->ser_type_description."','')";
		
		$sql = "INSERT INTO service_type (`ser_type_code_api`, `ser_type_name`, `ser_type_description`,`type_service`) VALUES ".$values;
		if($consulta = mysql_query($sql)){
				if($consulta){
					return mysql_insert_id();
				}
				else
					return -1;
			}
			 else{
				$sql =
				"UPDATE `service_type` SET 
				`ser_type_name`	= '".$data->ser_type_name."',
				`ser_type_description`	= '".$data->ser_type_description."' where ser_type_code_api=".$codigo;
				
				if($consulta = mysql_query($sql)){
				
					 if($consulta){
							return $this->getServiceTypeCodeByServiceTypeCodeApi($codigo);
						}
						else{
							return -1;
						}
				}
				else{
						securityMasterUnlock(65,1,$sql);
						return false;
					}
			 
			 }	
			}
		 else{
					securityMasterUnlock(65,1,$sql);
					return false;
				}
	}
	
	
	
   /**
	 * Esta funcion se encarga de obtener el código del tipo del servicio por el código del tipo de servicio de asigando por la api		    
	 * @access public
	 * @return Código del tipo de servicio asignado por bd
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function getServiceTypeCodeByServiceTypeCodeApi($ser_type_code_api)
	{
	
		$where= " WHERE ser_type_code_api =".$ser_type_code_api;
		
			$sql = "SELECT ser_type_code FROM service_type ".$where;
		    if($consulta = mysql_query($sql)){
		
					if($row=mysql_fetch_array($consulta))
					{
						$serviceTypeCode			= $row['ser_type_code'];
					
					}else{
						$serviceTypeCode=0;
					}
					
				return $serviceTypeCode;
			}
			else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	
	}

	/**
	 * Esta funcion se encarga de obtener el código de la api por su nombre		    
	 * @access public
	 * @return Código de la api
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function getCodeApiByName($name)
	{
	
		$where= " WHERE api_name ='".$name."'";
		
			$sql = "SELECT api_code FROM api ".$where;
		    if($consulta = mysql_query($sql)){
		
					if($row=mysql_fetch_array($consulta))
					{
						$apiCode			= $row['api_code'];
					
					}else{
						$apiCode=0;
					}
					
				return $apiCode;
			}
			else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	
	}
	
	
	
 	/**
	 * Esta funcion se encarga de obtener un tipo de servicio por su identificador único obtenidos desde la api    
	 * @access public
	 * @return false si no existe ningún registro, true si existe un registro
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function existServiceTypeByCode($code)
	{
		$where= "WHERE ser_type_code_api=".$code;
		
			$sql = "SELECT * FROM service_type ".$where;
		    if($consulta = mysql_query($sql)){
		
					$data = array();	
					$i=0;
					while($row=mysql_fetch_array($consulta))
					{
						$i++;
					}
					if($i==0){
						return false;
					}
					else{
						return true; 
					}
			}
			else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
     /**
	 * Esta funcion se encarga de obtener todos los servicios activos .		    
	 * @access public
	 * @return array con los datos de todos los servicios encontrados
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function listServicesType($type='')
	{
		$where= '';
		if($type!='')
			$where .= " WHERE `type_service`='".$type."'";
		$sql = "SELECT * FROM service_type ".$where." ORDER BY ser_type_name";
		if($consulta = mysql_query($sql)){
	
			$data = array();	
			$i=0;
			while($row=mysql_fetch_array($consulta))
			{
				$data[$i]->serviceTypeCode			= $row['ser_type_code'];
				$data[$i]->serviceTypeName			= $row['ser_type_name'];
				$data[$i]->type_service				= $row['type_service'];
				
				$i++;
			}
				
			return $data;
		}
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
		
	}
	
   /**
	 * Esta funcion se encarga de insertar en la tabla liberations y además retorna el identificador del registro insertado .		    
	 * @access public
	 * @return identificador del nuevo registro de liberación
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function saveLiberation($data){
		 $sql="INSERT INTO liberations (ser_code, cli_code, lib_date,lib_country,lib_model,lib_operator,lib_numMep,lib_id,lib_user,lib_serie,lib_id_box,lib_description, lib_nick, lib_pass, lib_imei,lib_rm) VALUES ";
		 $sql.="($data->idService,$data->idUser, '".date("Y-m-d H:i:s")."','".$data->country."','".$data->model."','".$data->operator."','".$data->numMep."','".$data->id."','".$data->user."','".$data->serie."','".$data->idBox."','".$data->description."','".$data->lib_nick."','".$data->lib_pass."','".$data->lib_imei."','".$data->lib_rm."')";
		
		if(mysql_query($sql))
			return mysql_insert_id();
	    else{
				securityMasterUnlock(65,1,$sql);
				return "null";
			}
	}
	
	
/**
	 * Esta funcion se encarga de insertar en la tabla operator_notice		    
	 * @access public
	 * @return 
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function saveAllImeis($dataImei)
	{	
		include_once("RijndaelHex.php");
		$rijndael = new RijndaelHex();
		
		switch($dataImei->payForm)
		{
			case 'Pesos Colombianos': $dataImei->payForm = 'COL';
									  break;
			case 'Bolivares'		: $dataImei->payForm = 'BOL';
									  break;
			case 'Dolares'			: $dataImei->payForm = 'USD';
									  break;
		}
		
		$sqlAntes="INSERT INTO liberations_imei (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status,	libimei_money, libimei_price_purchase,libimei_ip) VALUES ";
		$sqlAntes.="($dataImei->idLiberation,'".$rijndael->linencrypthex($dataImei->imei)."', '".date("Y-m-d H:i:s")."','".$dataImei->price."',0,'".$dataImei->payForm."', '".str_replace(",",".",$dataImei->libimei_price_purchase)."','".$_SERVER['REMOTE_ADDR']."')";
		
		mysql_query($sqlAntes);
		
		
		$sql="INSERT INTO operator_notice (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status,	libimei_money, libimei_price_purchase,libimei_ip) VALUES ";
		$sql.="($dataImei->idLiberation,'".$rijndael->linencrypthex($dataImei->imei)."', '".date("Y-m-d H:i:s")."','".$dataImei->price."',0,'".$dataImei->payForm."', '".str_replace(",",".",$dataImei->libimei_price_purchase)."','".$_SERVER['REMOTE_ADDR']."')";
		//die($sql);
		if(mysql_query($sql))
			return mysql_insert_id();
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	
/**
	 * Esta funcion se encarga de obtener todos los servicios asociados a cada tipo de servicio existente en el sistema.		    
	 * @access public
	 * @return array con los datos de todos los servicios encontrados
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function listAllServiceByServiceType($type = '')
	{
		
		$where= '';
		if(isset($type) && $type != '')
			$where = " WHERE type_service = '".$type."'";
		
		$sql      = "SELECT * FROM  service_type  ".$where." ORDER BY ser_type_name";
		if($consultaServiceType = mysql_query($sql)) {
		
				$data = array();	
				$listServiceByServiceType= array();
				$i=0;
				while($row=mysql_fetch_array($consultaServiceType))
				{
					$data[$i]->ser_type_code			= $row['ser_type_code'];
					$data[$i]->ser_type_name			= $row['ser_type_name'];
					$data[$i]->ser_type_name_e			= $row['ser_type_name_e'];
					
					$sql = "SELECT * FROM services where ser_type_code = ".$row['ser_type_code']." and ser_status='1' ORDER BY ser_name ASC, ser_price ASC";
					
					if($consultaService = mysql_query($sql)){
							$j=0;
							$dataService = array();
								while($rowService=mysql_fetch_array($consultaService)){
									
									$dataService[$j]->code          	= $rowService['ser_code'];
									$dataService[$j]->ser_type_code 	= $rowService['ser_type_code'];
									$dataService[$j]->ser_type_code_api = @$rowService['ser_type_code_api'];
									$dataService[$j]->name          	= $rowService['ser_name'];
									$dataService[$j]->name_e          	= $rowService['ser_name_e'];
									$dataService[$j]->info_large    	= $rowService['ser_info_large'];
									$dataService[$j]->info_short    	= $rowService['ser_info_short'];
									$dataService[$j]->req_country   	= ($rowService['ser_req_country'] =='1')?'SI':'NO';
									$dataService[$j]->req_operator  	= ($rowService['ser_req_operator']=='1')?'SI':'NO';
									$dataService[$j]->req_models    	= ($rowService['ser_req_models']  =='1')?'SI':'NO';
									$dataService[$j]->req_MEP       	= ($rowService['ser_req_MEP']     =='1')?'SI':'NO';
									$dataService[$j]->price_col      	= $rowService['ser_price'];
									$dataService[$j]->price_bol      	= $rowService['ser_price_bol'];
									$dataService[$j]->price_usd      	= $rowService['ser_price_us'];
									
									$j++;
								}
							$data[$i]->listServices = $dataService;
							
							
							$i++;
					}
					else{
						securityMasterUnlock(65,1,$sql);
						return false;
					}
				}
				/*echo "<pre>";	
				print_r($data);	
				echo "</pre>";*/
				return $data;
		}
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
		
	}
	
	/////////////////////////////////////////////////////////
	//	newServiceType : funcion encargada de agregar un nuevo tipo de servicio.
	//	@parameter     : data-> son los datos del nuevo tipo de servicio.
	/////////////////////////////////////////////////////////
	function newServiceType($data){
		$sql = "
		INSERT INTO `service_type` (
		`ser_type_code` ,
		`ser_type_name` ,
		`ser_type_description` ,
		`type_service`,
		`ser_type_name_e`,
		`ser_type_description_e`
		)
		VALUES (
		NULL , 
		'".$data->ser_type_name."', 
		'".$data->ser_type_description."',
		'".$data->type_service."', 
		'".$data->ser_type_name_e."', 
		'".$data->ser_type_description_e."');";
		
		if(mysql_query($sql))
			return mysql_insert_id();
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	//////////////////////////////////////////////////////////////////////////
	// funcion encargada de actualizar los datos de un tipo de servicio.
	//////////////////////////////////////////////////////////////////////////
	function updateServiceType($data)
	{		
		$sql = "
		UPDATE `service_type` SET `ser_type_name` = '".$data->name."',
		`ser_type_description` = '".$data->description."',
		`type_service` = '".$data->type_service."',
		`ser_type_name_e` = '".$data->name_e."',
		`ser_type_description_e` = '".$data->description_e."'  
		 WHERE `ser_type_code` =".$data->code_type_serv;
		
		if(mysql_query($sql))
			return mysql_insert_id();
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	//////////////////////////////////////////////////////////////////////////
	// funcion encargada de actualizar los datos de un tipo de servicio.
	//////////////////////////////////////////////////////////////////////////
	function getDataServiceType($code_type_serv)
	{
		$sql = "SELECT * FROM service_type WHERE ser_type_code=".$code_type_serv;
		
		if($consult = mysql_query($sql)){
			$row     = mysql_fetch_array($consult);
			
			$data->code 		= $row['ser_type_code'];
			$data->name 		= $row['ser_type_name'];
			$data->description 	= $row['ser_type_description'];
			$data->name_e 		= $row['ser_type_name_e'];
			$data->description_e= $row['ser_type_description_e'];
			$data->type_service	= $row['type_service'];
			
			return $data;
		}
		else{
			securityMasterUnlock(65,1,$sql);
			return false;
		}
	}
	
	//////////////////////////////////////////////////////////////////////////////////
	// listTypeService: Esta funcion es la encargada de listar los tipos de servicios que existen en el sitio.
	///////////////////////////////////////////////////////////////////////////////		
	function listTypeService($inicio = 0,$cantidad = 0,$search='',$order_by='', $type_service = 'All'){
		$where = '';
		
		if($order_by == '')
			$order_by = " ORDER BY ser_type_order ";
		
		if($search != '')
			$where = " WHERE (ser_type_name like '%".$search."%' OR type_service like '%".$search."%') ";
		
		if($type_service != 'All'){
			if($where == '')
				$where = " WHERE type_service='".$type_service."' ";
			else			
				$where .= " AND type_service='".$type_service."' ";
		}
		
		$sql = "SELECT * FROM service_type ".$where.' '.$order_by." LIMIT ".$inicio.",".$cantidad;
		
		if($consult  = mysql_query($sql)){
			$data = array();
			$i = 0;
			while($row = mysql_fetch_array($consult)){
				$data[$i]->code     		= $row['ser_type_code'];
				$data[$i]->name     		= $row['ser_type_name'];
				$data[$i]->description  	= $row['ser_type_description'];
				$data[$i]->name_e     		= $row['ser_type_name_e'];
				$data[$i]->description_e  	= $row['ser_type_description_e'];
				$data[$i]->type_service 	= $row['type_service'];
				$data[$i]->ser_type_order 	= $row['ser_type_order'];
				$data[$i]->amount_serv		= $this->getAmountServiceByType($data[$i]->code);
				
				$i++;				
			}
			return $data;
		}
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}			
	
	/////////////////////////////////////////////////////////
	//	countTypeService : funcion encargada de contar los tipos de servicio que existen en el sitio
	/////////////////////////////////////////////////////////
	public function countTypeService($search='', $type_service = 'All'){
		$where = '';
		if($search != 'All')
			$where = " WHERE (ser_type_name like '%".$search."%' OR type_service like '%".$search."%')";
		
		if($type_service != 'All'){
			if($where == '')
				$where = " WHERE type_service='".$type_service."' ";
			else			
				$where .= " AND type_service='".$type_service."' ";
		}
		
		$sql = "SELECT count(*) as cant FROM service_type ".$where;
	
		if($consulta = mysql_query($sql)){
			$row = mysql_fetch_array($consulta);
				
			return $row['cant'];
		}
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	
	function getAmountServiceByType($code_type_service)
	{
		$sql = "SELECT count(*) AS cant FROM services WHERE ser_type_code=".$code_type_service;		
	
		if($consulta = mysql_query($sql)){
			$row = mysql_fetch_array($consulta);
				
			return $row['cant'];
		}
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	
	
	function deleteServiceType($code_type_service)
	{
		$sql= "DELETE FROM `service_type` WHERE `ser_type_code` = ".$code_type_service;
		if(mysql_query($sql))
		   return true;
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}   
	}
	
	/**
	 * Esta funcion se encarga de insertar en la tabla operator_notice		    
	 * @access public
	 * @return 
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function saveAllCable($data)
	{	
	
		switch($data->payForm)
		{
			case 'Pesos Colombianos': $data->payForm = 'COL';
									  break;
			case 'Bolivares'		: $data->payForm = 'BOL';
									  break;
			case 'Dolares'			: $data->payForm = 'USD';
									  break;
		}
		
		$sqlAntes="INSERT INTO liberations_imei (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status,	libimei_money, libimei_price_purchase) VALUES ";
		$sqlAntes.="($data->idLiberation,'', '".date("Y-m-d H:i:s")."','".$data->price."',0,'".$data->payForm."', '".str_replace(",",".",$data->libimei_price_purchase)."')";
		mysql_query($sqlAntes);
		
		$sql="INSERT INTO operator_notice (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status,	libimei_money, libimei_price_purchase) VALUES ";
		$sql.="($data->idLiberation,'', '".date("Y-m-d H:i:s")."','".$data->price."',0,'".$data->payForm."', '".str_replace(",",".",$data->libimei_price_purchase)."')";
		
		
		if(mysql_query($sql))
		   return true;
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	/**
	 * Esta funcion se encarga de insertar en la tabla operator_notice		    
	 * @access public
	 * @return 
	 *//////////////////////////////////////////////////////////////////////////////////			
	
	public function saveAllFile($data)
	{	
	
		switch($data->payForm)
		{
			case 'Pesos Colombianos': $data->payForm = 'COL';
									  break;
			case 'Bolivares'		: $data->payForm = 'BOL';
									  break;
			case 'Dolares'			: $data->payForm = 'USD';
									  break;
		}
		
		$sqlAntes = "INSERT INTO liberations_imei (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status, libimei_money, libimei_original, libimei_renombre,
				libimei_price_purchase) VALUES ";
		$sqlAntes.="($data->idLiberation,'', '".date("Y-m-d H:i:s")."','".$data->price."',0,'".$data->payForm."','".$data->file_name."','".$data->file_rename."', '".str_replace(",",".",$data->libimei_price_purchase)."')";	
		
		mysql_query($sqlAntes);
		
		
		$sql = "INSERT INTO operator_notice (lib_code,libimei_number,libimei_date,libimei_bonus,libimei_status, libimei_money, libimei_original, libimei_renombre,
				libimei_price_purchase) VALUES ";
		$sql.="($data->idLiberation,'', '".date("Y-m-d H:i:s")."','".$data->price."',0,'".$data->payForm."','".$data->file_name."','".$data->file_rename."', '".str_replace(",",".",$data->libimei_price_purchase)."')";	
		
		if(mysql_query($sql))
		   return true;
		else{
				securityMasterUnlock(65,1,$sql);
				return false;
			}
	}
	
	/**
	 * Esta funcion se encarga de obtener todos los servicios asociados a cada tipo de servicio existente en el sistema.		    
	 * @access public
	 * @return array con los datos de todos los servicios encontrados
	 *//////////////////////////////////////////////////////////////////////////////////			
	function listAllServiceByServiceTypePublic2 ($idi = 1,$typeM='COL'){
		$sql = "
			SELECT st.ser_type_code, st.ser_type_name, st.ser_type_name_e, st.type_service, s.ser_code, s.ser_name, s.ser_name_e ,s.ser_price,
			s.ser_price_us, s.ser_price_bol, s.ser_time_response
			FROM service_type st 
			JOIN services s ON st.ser_type_code=s.ser_type_code AND s.ser_status = 1 ORDER BY st.ser_type_order, s.ser_order;";
		$array_imei = $array_cable = $array_archivo = array();
		if($result = mysql_query($sql)){
			$data;
			$i = $i_imei = $i_cable = $i_archivo = 0;
			while($row = mysql_fetch_array($result)){
				$data[$i]->type_service = $row["type_service"];
				$data[$i]->ser_code = $row["ser_code"];
				$data[$i]->ser_type_code = $row["ser_type_code"];
				$data[$i]->ser_time_response = $row["ser_time_response"];
				switch($idi){
					case 1:
						$data[$i]->service_name = $row["ser_name"];
						$data[$i]->service_type_name = $row["ser_type_name"];
						break;
					case 2:
						$data[$i]->service_name = $row["ser_name_e"];
						$data[$i]->service_type_name = $row["ser_type_name_e"];
						break;
					
					default:
						$data[$i]->service_name = $row["ser_name"];
						$data[$i]->service_type_name = $row["ser_type_name"];
						break;
				}
				
				switch($typeM)
				{
					case 'COL': 
						$data[$i]->service_price = $row['ser_price']." COL";
						break;
					case 'USD': 
						$data[$i]->service_price = $row['ser_price_us']." USD";
						break;
					case 'BOL':
						$data[$i]->service_price = $row['ser_price_bol']." BOL";
						break;
					default:
						$data[$i]->service_price = $row['ser_price']." COL";
						break;
				}
				
				switch($row['type_service'])
				{
					case 'Imei': 
						$array_imei[$i_imei] = $data[$i];
						$i_imei++;
						break;
					case 'Cable': 
						$array_cable[$i_cable] = $data[$i];
						$i_cable++;
						break;
					case 'Archivo':
						$array_archivo[$i_archivo] = $data[$i];
						$i_archivo++;
						break;
				}
				
				$i++;
			}
			return array($array_imei,$array_cable,$array_archivo);
		}
		else{
			securityMasterUnlock(65,1,$sql);
			return false;
		}
	}	
	
	
	public function listAllServiceByServiceTypePublic($idi = 1,$typeM='COL')
	{
		$arreglo = '';
		$arreglo1 = '';
		$arreglo2 = '';
		$where= '';

		$where = " WHERE type_service = 'Imei";
		
		$sql      = "SELECT * FROM  service_type  ".$where." ORDER BY ser_type_name";
		if($consultaServiceType = mysql_query($sql)){
				$arreglo .='<div class="table">';
				$arreglo1 .='<div class="table">';
				$arreglo2 .='<div class="table">';
				while($row=mysql_fetch_array($consultaServiceType))
				{	
					if(isset($idi) && $idi == 2)
					{
						$arreglo .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name_e'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Price</strong></div>
							<div class="colm" style="width:140px;"><strong>Delivery Time</strong></div>
							</div>
							
							
						';
						$arreglo1 .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name_e'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Price</strong></div>
							<div class="colm" style="width:140px;"><strong>Delivery Time</strong></div>
							</div>
							
							
						';
						$arreglo2 .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name_e'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Price</strong></div>
							<div class="colm" style="width:140px;"><strong>Delivery Time</strong></div>
							</div>
							
							
						';
					}
					else
					{
						$arreglo .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Precio</strong></div>
							<div class="colm" style="width:140px;"><strong>Tiempo Liberación</strong></div>
							</div>
							
							
						';
						
						$arreglo1 .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Precio</strong></div>
							<div class="colm" style="width:140px;"><strong>Tiempo Liberación</strong></div>
							</div>
							
							
						';
						
						$arreglo2 .= '
							
							
							
							<div class="div-top">
							<div class="colm" style="width:550px;"><strong>'.$row['ser_type_name'].'</strong></div>
							<div class="colm" style="width:150px;"><strong>Precio</strong></div>
							<div class="colm" style="width:140px;"><strong>Tiempo Liberación</strong></div>
							</div>
							
							
						';
					}
					
					$sql = "SELECT * FROM services where ser_type_code = ".$row['ser_type_code']." and ser_status='1' ORDER BY ser_name";			
					if($consultaService = mysql_query($sql)){
					
						$arreglo .= '<div class="rows">';
						$arreglo1 .= '<div class="rows">';
						$arreglo2 .= '<div class="rows">';
						while($rowService=mysql_fetch_array($consultaService))
						{							
							switch($typeM)
							{
								case 'COL': $price = $rowService['ser_price']." COL";
											break;
								case 'USD': $price = $rowService['ser_price_us']." USD";
											break;
								case 'BOL': $price = $rowService['ser_price_bol']." BOL";
											break;
							}
							
							if(isset($idi) && $idi == 2)
							{
								$arreglo .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name_e'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
								
								$arreglo1 .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name_e'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
								
								$arreglo2 .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name_e'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
							}
							else
							{
								$arreglo .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
								
								$arreglo1 .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
								
								$arreglo2 .='
											
											
											<div class="rows">  
											<div class="colm" style="width:550px;">'.$rowService['ser_name'].'</div>
											<div class="colm" style="width:150px;">'.$price.'</div>
											<div class="colm" style="width:140px;">'.$rowService['ser_time_response'].'</div></div>
											
								';
							}
						}
						$arreglo .= '</div>';
						$arreglo1 .= '</div>';
						$arreglo2 .= '</div>';
					}
					else{
						securityMasterUnlock(65,1,$sql);
						return false;
					}
				}
				$arreglo .= '</div>';
				$arreglo1 .= '</div>';
				$arreglo2 .= '</div>';
				return array($arreglo,$arreglo1,$arreglo2);
		}
		else{
			securityMasterUnlock(65,1,$sql);
			return false;
		}		
	}
	
	/**
	*	Función encargada de eliminar una liberacion
	*	@autor: JSL
	*	@date: 07 NOV 2011
	*/
	function deleteUnlock($lib_code){
		$sql= "DELETE FROM liberations WHERE lib_code=".(int) $lib_code.";";
		return mysql_query($sql);
	}
		
	/**
	*	Funcion encargada de retornar un arreglo con los numeros de orden usados por los grupos.
	*	@autor: JSL
	*	@date: 02/01/2012
	*/
	function getArrayOrdersSer_type($type_service){
		$sql = "SELECT st.ser_type_order FROM service_type st WHERE st.type_service='".$type_service."' GROUP BY st.ser_type_order;";
		if($result = mysql_query($sql)){
			$i = 0;
			while($row = mysql_fetch_array($result)){
				$data[$i] = $row["ser_type_order"];
				$i++;
			}
			return $data;
		}
		else{
			securityMasterUnlock(65,1,$sql);
			return NULL;
		}
	}
	
	/**
	*	Funcion encargada de modificar el orden para grupo.
	*	@autor: JSL
	*	@date: 02/01/2011
	*/
	function updateOrderServiceType($data){
		$sql = "UPDATE service_type SET ser_type_order = '".$data->ser_type_order."' WHERE ser_type_code=".$data->ser_type_code;
		if( mysql_query($sql) ){
			return true;	
		}
		else{
			securityMasterUnlock(65,1,$sql);
			return NULL;
		}
	}	
}	
?>